﻿Imports BUS
Imports DAO
Imports DTO
Imports DevComponents.DotNetBar

Public Class frmDanhSachKhachHang

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub frmDanhSachKhachHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        hienthidanhsach()
    End Sub

    Public Sub hienthidanhsach()
        dgwDanhSachKhachHang.DataSource = KhachHangDAO.GetKhachHangAll()
    End Sub

    Private Sub radTatCa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTatCa.CheckedChanged
        txtTimKiemKhachHang.Text = "0"
        'timkiemdienthoai()
        hienthidanhsach()
    End Sub


    Private Sub txtTimKiemKhachHang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTimKiemKhachHang.TextChanged
        If radTenKH.Checked = True Then
            timkiemtenkh()
        End If
        If radDiaChi.Checked = True Then
            timkiemdiachi()
        End If
        If radDienThoai.Checked = True Then
            timkiemdienthoai()
        End If
        If radEmail.Checked = True Then
            timkiememail()
        End If
    End Sub

    Public Sub timkiemtenkh()

        Dim kh As New KhachHangDTO()
        kh.HoTenKhachHang = txtTimKiemKhachHang.Text
        dgwDanhSachKhachHang.DataSource = KhachHangDAO.SelectKhachHangLikeTen(kh)
    End Sub
    Public Sub timkiemdiachi()

        Dim kh As New KhachHangDTO()
        kh.DiaChi = txtTimKiemKhachHang.Text
        dgwDanhSachKhachHang.DataSource = KhachHangDAO.SelectKhachHangLikeDiaChi(kh)
    End Sub
    Public Sub timkiememail()

        Dim kh As New KhachHangDTO()
        kh.Email = txtTimKiemKhachHang.Text
        dgwDanhSachKhachHang.DataSource = KhachHangDAO.SelectKhachHangLikeEmail(kh)
    End Sub
    Public Sub timkiemdienthoai()
        Dim kh As New KhachHangDTO()
        Try
            kh.DienThoai = Int64.Parse(txtTimKiemKhachHang.Text)
        Catch e1 As FormatException
            MessageBoxEx.Show("Ðiện thoại phải nhập vào số", "Thông báo")
            Return
        End Try
        dgwDanhSachKhachHang.DataSource = KhachHangDAO.SelectKhachHangLikeDienThoai(kh)
    End Sub

    Private Sub radEmail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radEmail.CheckedChanged
        timkiememail()
    End Sub

    Private Sub radDiaChi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radDiaChi.CheckedChanged
        timkiemdiachi()
    End Sub

    Private Sub radTenKH_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTenKH.CheckedChanged
        timkiemtenkh()
    End Sub

    Private Sub btnChon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChon.Click
        If dgwDanhSachKhachHang.SelectedRows.Count > 0 Then
            frmPhieuThuTien.makh = dgwDanhSachKhachHang.SelectedRows(0).Cells(0).Value.ToString()
            frmHoaDonBanSach.MaKH = dgwDanhSachKhachHang.SelectedRows(0).Cells(0).Value.ToString()
        End If
        Me.Close()
    End Sub
End Class